import { request } from '../../utils/request'

Page({
  data: {
    page: 1,
    size: 10,
    status: '0',
    showNoMore: false,
    showLoading: false,
    dataList: []
  },
  onLoad(options) {},

  onChange(event) {
    console.log()
    this.setData({
      status: event.detail.name
    })
    this.setData({
      page: 1,
      size: 10
    })
    this.getDataList()
  },

  getDataList() {
    request({
      url: '/mini/api/mine/queryCoupons',
      method: 'POST',
      data: {
        page: this.data.page,
        size: this.data.size,
        status: Number(this.data.status)
      }
    }).then((resdata) => {
      if (resdata.code == 200) {
        let newData = this.data.showLoading
          ? this.data.dataList.concat(
              resdata.data.data
            )
          : resdata.data.data
        let showNoMore =
          resdata.data.data.length < 10
        this.setData({
          dataList: newData || [],
          showLoading: false,
          showNoMore: showNoMore
        })
      } else {
        this.setData({
          dataList: [],
          showLoading: false,
          showNoMore: false
        })
        wx.showToast({
          title: resdata.message,
          icon: 'none'
        })
      }
    })
  },

  receiveCoupon() {
    wx.navigateTo({
      url: '/packageMy/coupon/coupon'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDataList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {}
})
